package com.haipumi.back.actions;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import com.haipumi.beans.DataGrid;
import com.haipumi.beans.haipumi_reply;
import com.haipumi.biz.IBackTaskReplyBiz;
import com.haipumi.biz.impl.BackTaskReplyBizImpl;
import com.haipumi.servlets.CommonServlet;
import com.haipumi.utils.RequestUtil;

public class BackTaskReplyServlet extends CommonAction {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 879979291922320410L;
	
	@Autowired
	IBackTaskReplyBiz backTaskReplyBiz;
	
	private DataGrid dg=new DataGrid();

	public DataGrid getDg() {
		return dg;
	}

	public void setDg(DataGrid dg) {
		this.dg = dg;
	}

	public String doTaskReply(){
		String op=request.getParameter("op");
		if(!"".equals(op)&&op!=null){
			if("findAllTaskReply".equals(op)){
				findAllTaskReply(request,response);
			}else if("saveTaskReply".equals(op)){
				saveTaskReply(request,response);
			}else if("editTaskReply".equals(op)){
				editTaskReply(request,response);
			}
		}
		return super.SUCCESS;
	}

	private void editTaskReply(HttpServletRequest request,
			HttpServletResponse response) {
		haipumi_reply reply=null;
		PrintWriter out=null;
		try {
			out=response.getWriter();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		reply=RequestUtil.parseRequest(request, haipumi_reply.class);
		haipumi_reply backreply=backTaskReplyBiz.editReply(reply);
		if(backreply!=null){
			//成功更改
		}else{
			//改失败
			backreply=backTaskReplyBiz.findreply(reply.getUid());
		}
	}

	private void saveTaskReply(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		
	}

	private void findAllTaskReply(HttpServletRequest request,
			HttpServletResponse response) {
		List<haipumi_reply>replylist=backTaskReplyBiz.findAllTaskReply(start,end,sort,order);
		int r=backTaskReplyBiz.countTaskReply(start,end,sort,order);
		dg.setRows(replylist);
		dg.setTotal(r);
	}

}
